<!--老师查看自己发布的校内题目列表和有关的题目列表-->
<style>
	.yanse {
		width: 20px;
		height: 20px;
		display: inline-block;
		line-height: 20px;
	}
	
	.input-group {
		margin-bottom: 20px;
	}
	
	.wenxintishi {
		margin-bottom: 20px;
	}
	
	.xiaofangkuai {
		display: inline-block;
	}
	
	#xinxi {
		height: 100px;
	}
	
	#bishe_content {
		height: 100px;
	}
	
	.td_change {
		cursor: pointer;
	}
	.td_change2 {
		cursor: pointer;
	}
</style>

<!-- 修改毕设模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">修改毕设题目</h4>
			</div>
			<div class="modal-body">
				<div class="input-group">
					<span class="input-group-addon" id="ketimingcheng">毕设名称</span>
					<input id="bishe_title" type="text" class="form-control" placeholder="请修改毕设名称" aria-describedby="ketimingcheng">
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="ketixinxi">毕设信息</span>
					<textarea class="form-control" type="text" name="bishe_content" id="bishe_content" placeholder="请修改毕设信息" aria-describedby="ketixinxi"></textarea>
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="ketiyaoqiu">毕设要求</span>
					<textarea class="form-control" type="text" name="bishe_demand" id="bishe_demand" placeholder="请修改毕设要求" aria-describedby="ketiyaoqiu"></textarea>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" data-dismiss="modal" id="bishe_xiugai">确定修改</button>
			</div>
		</div>
	</div>
</div>
<!-- 添加毕设模态框 -->
<div class="modal fade" id="tianjiaketi" tabindex="-1" role="dialog" aria-labelledby="tianjiaketi1">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="tianjiaketi1">添加毕设题目</h4>
			</div>
			<div class="modal-body">
				<div class="input-group">
					<span class="input-group-addon" id="ketimingcheng1">毕设名称</span>
					<input id="mingcheng" type="text" class="form-control" placeholder="请添加毕设名称" aria-describedby="ketimingcheng">
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="ketixinxi1">毕设信息</span>
					<textarea id="xinxi" class="form-control" type="text" name="" placeholder="请添加毕设信息" aria-describedby="ketixinxi"></textarea>
				</div>
				<div class="input-group">
					<span class="input-group-addon" id="ketiyaoqiu1">毕设要求</span>
					<textarea id="yaoqiu" class="form-control" type="text" name="" placeholder="请添加毕设要求" aria-describedby="ketiyaoqiu"></textarea>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary teacher_add" data-dismiss="modal">确定添加</button>
			</div>
		</div>
	</div>
</div>

<div class="wenxintishi">
	<div class="xiaofangkuai">
		<div class="yanse alert-danger"></div><span>待审核状态</span>
	</div>
	<div class="xiaofangkuai">
		<div class="yanse alert-success"></div><span>已审核状态</span>
	</div>
	<button style="float: right;" type="button" class="btn btn-primary" data-toggle="modal" data-target="#tianjiaketi">添加毕设</button>
	<button style="float: right; margin-right:20px" class="btn btn-primary" id="xuanbaoall">导出选报情况表</button>
</div>

<div class="tabbable" id="tabs_">
	<ul class="nav nav-tabs">
		<li class="active">
			<a href="#panel_1" data-toggle="tab" id="chufa_1">校内题目</a>
		</li>
		<li>
			<a href="#panel_2" data-toggle="tab" id="chufa_2">校外题目</a>
		</li>
	</ul>
	<div class="tab-content">
		<div class="tab-pane active" id="panel_1">
			<table class="table table-bordered table-hover" id="table_1">
				<thead>
					<tr>
						<th col style="width: 50%">毕设名称</th>
						<th col style="width: 20%">已报毕设学生</th>
						<th col style="width: 30%">对毕设的操作 </th>
					</tr>
				</thead>
			</table>
			<!-- 分页 -->
			<nav aria-label="...">
				<ul class="pager">
					<li>
						<a href="#" id="pre1">上一页</a>
					</li>
					<li>
						<a href="#" id="top1">首页</a>
					</li>
					<li>第<span class="num1">1</span>页</li>
					<li>
						<a href="#" id="end1">尾页</a>
					</li>
					<li>
						<a href="#" id="next1">下一页</a>
					</li>
				</ul>
			</nav>
		</div>
		<div class="tab-pane" id="panel_2">
			<table class="table table-bordered table-hover" id="table_2">
				<thead>
					<tr>
						<th col style="width: 50%">毕设名称</th>
						<th col style="width: 20%">已报毕设学生</th>
						<th col style="width: 30%">对毕设的操作 </th>
					</tr>
				</thead>
			</table>
			<!-- 分页-->
			<nav aria-label="...">
				<ul class="pager">
					<li>
						<a href="#" id="pre2">上一页</a>
					</li>
					<li>
						<a href="#" id="top2">首页</a>
					</li>
					<li>第<span class="num2">1</span>页</li>
					<li>
						<a href="#" id="end2">尾页</a>
					</li>
					<li>
						<a href="#" id="next2">下一页</a>
					</li>
				</ul>
			</nav>
		</div>
	</div>
</div>

<script>
	var pageNum = 1;
	var pageSize = 15;

	var myajax;
	
	$('#chufa_1').click(function(){
		xiaonei_(1)
	})

	$('#chufa_2').click(function(){
		xiaowai_(1)
	})

	$(function() {// 初始化内容
		$('#chufa_1').trigger("click")
    })

	$("#top1").click(function() {
		xiaonei_(1);
	})
	$("#end1").click(function() {
		xiaonei_($.session.get("totalPageNum"));
	})
	$("#pre1").click(function() {
		xiaonei_($.session.get("prePageNum"));
	})
	$("#next1").click(function() {
		xiaonei_($.session.get("nextPageNum"));
	})
	
	$("#top2").click(function() {
		xiaowai_(1);
	})
	$("#end2").click(function() {
		xiaowai_($.session.get("totalPageNum"));
	})
	$("#pre2").click(function() {
		xiaowai_($.session.get("prePageNum"));
	})
	$("#next2").click(function() {
		xiaowai_($.session.get("nextPageNum"));
	})


	function xiaonei_(pageNum) {
		myajax = $.ajax({ //校内题目
			xhrFields: {
				withCredentials: true
			},
			type: 'get',
			url: getFullURL('teacher/topic-exlist'),
			data: {
				pageNum: pageNum,
				pageSize: pageSize
			},
			dataType: 'json',
			success: function(data) {
				console.log(data)
				if(data.status == 0) {
					$.session.set("prePageNum", data.page.prePageNum);
					$.session.set("nextPageNum", data.page.nextPageNum);
					$.session.set("totalPageNum", data.page.totalPageNum);
					$('.num1').html(data.page.pageNum);
					
					$('#table_1').html(`<thead>
						<tr>
							<th col style="width: 50%">毕设名称</th>
							<th col style="width: 20%">已报毕设学生</th>
							<th col style="width: 30%">对毕设的操作 </th>
						</tr>
					</thead>`);
					
					$.each(data.page.list, function(i, n) {
						var student_baoming = ``;
						$.each(n.students, function(k, j) {
							var baoming = `<option value='` + j.sno + `'>` + j.name + `</option>`
							student_baoming = student_baoming + baoming;
						})
						var table_content = `<tr id="tr_` + n.gid + `" class="alert-danger tr_class">
				        <td class="td_change" value="` + n.gid + `">` + n.topic + `</td>
				        <td><select class="form-control" id="select_` + n.gid + `">
				                ` + student_baoming + `
				            </select>
				        </td>
				        <td  id="td_` + n.gid + `">
				            <div class="btn-group xiaoneianniu" role="group" aria-label="...">
				                <button type="button" class="btn btn-default pass" value='` + n.gid + `'>通过</button>
				                <button type="button" class="btn btn-default change" value='` + n.gid + `'>修改</button>
				                <button type="button" class="btn btn-default shanchu" value='` + n.gid + `'>删除</button>
				                <button type="button" class="btn btn-default nopass" value='` + n.gid + `'>不通过</button>
				            </div>
				        </td>
				    </tr>`

						$('#table_1').append(table_content);

						if(n.shenhe == 2) {
							var tr_id = "#tr_" + n.gid;
							var td_id = "#td_" + n.gid;
							$(tr_id).removeClass('alert-danger');
							$(tr_id).addClass('alert-success');
							$(td_id).html("");
							$(td_id).html("审核通过");
						}
					})
					
					caozuo();
				} else {
					console.log('无数据')
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	}

	function xiaowai_(pageNum) {
		myajax = $.ajax({ //校外题目
			xhrFields: {
				withCredentials: true
			},
			type: 'get',
			url: getFullURL('teacher/outtc-exlist'),
			data: {
				pageNum: pageNum,
				pageSize: pageSize
			},
			dataType: 'json',
			success: function(data) {
				console.log(data)
				if(data.status == 0) {
					$.session.set("prePageNum", data.page.prePageNum);
					$.session.set("nextPageNum", data.page.nextPageNum);
					$.session.set("totalPageNum", data.page.totalPageNum);
					$('.num2').html(data.page.pageNum);
					
					$('#table_2').html(`<thead>
						<tr>
							<th col style="width: 50%">毕设名称</th>
							<th col style="width: 20%">已报毕设学生</th>
							<th col style="width: 30%">对毕设的操作 </th>
						</tr>
					</thead>`);
					
					$.each(data.page.list, function(i, n) {
						var table_aftershool = `<tr id="otr_` + n.gid + `" class="alert-danger tr_class" style="height:51px;">
			        <td class="td_change2" data-toggle="modal" data-target="#chakanketi" value='` + n.gid + `'>` + n.topic + `</td>
			        <td>` + nullStr(n.name) + `</td>
				        <td id="otd_` + n.gid + `">
				        	<input type="hidden" id="hidden" value="` + n.sno + `">
				            <div class="btn-group xiaowaianniu" role="group" aria-label="...">
				                <button type="button" id='xwtongguo' class="btn btn-default" value='` + n.gid + `'>通过</button>
				                <button type="button" class="btn btn-default change2" value='` + n.gid + `'>修改</button>
				                <button type="button" id='xwbutongguo' class="btn btn-default" value='` + n.gid + `'>不通过</button>
				            </div>
				        </td>
				    </tr>`
						$('#table_2').append(table_aftershool);

						if(n.shenhe == 0 || n.shenhe == 2) {
							var tr_id = "#otr_" + n.gid;
							var td_id = "#otd_" + n.gid;
							$(tr_id).removeClass('alert-danger');
							$(tr_id).addClass('alert-success');
							if(n.shenhe == 2) {
								$(td_id).html("");
								$(td_id).html("审核通过");
							} else {
								$(td_id).html("");
								$(td_id).html("审核未通过");
							}
						}
					})
					
					caozuo();
				} else {
					console.log('无数据或请求失败')
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	}

	//////////////////////////////////////////////////////////   
	$('#tianjiaketi .teacher_add').click(function() {
		$.ajax({ //教师添加课题
			xhrFields: {
				withCredentials: true
			},
			type: 'post',
			url: getFullURL('teacher/add-topic'),
			data: {
				topic: $('#mingcheng').val(),
				content: $('#xinxi').val(),
				demand: $('#yaoqiu').val()
			},
			dataType: 'json',
			success: function(data) {
				console.log(data)
				if(data.status == 0) {
					alert('添加成功');
					setTimeout(function() {
						$('.center').html('');
						$('.center').load('./teachercampus.html');
					}, 300)
				} else {
					alert('添加失败')
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	})

	$('#xuanbaoall').click(function() {
		window.open(getFullURL('teacher/down-extc'));
	})

	function caozuo() {
		//修改毕设题目
		$('.change').click(function() {
			xiugai($(this).val())
			$.session.set("bishe_gid", $(this).val())
			$(myModal).modal({
				keyboard: true,
				show: true
			})
		})
		$('.td_change').click(function() {
			xiugai($(this).attr("value"))
			$.session.set("bishe_gid", $(this).attr("value"))
			$(myModal).modal({
				keyboard: true,
				show: true
			})
		})
		$('.change2').click(function() {
			xiugai($(this).val())
			$.session.set("bishe_gid", $(this).val())
			$(myModal).modal({
				keyboard: true,
				show: true
			})
		})
		$('.td_change2').click(function() {
			xiugai($(this).attr("value"))
			$.session.set("bishe_gid", $(this).attr("value"))
			$(myModal).modal({
				keyboard: true,
				show: true
			})
		})

		$('#bishe_xiugai').click(function() {
			$.ajax({ //修改毕设题目
				xhrFields: {
					withCredentials: true
				},
				type: 'post',
				url: getFullURL('teacher/update-topic'),
				data: {
					gid: $.session.get("bishe_gid"),
					topic: $('#bishe_title').val(),
					content: $('#bishe_content').val(),
					demand: $('#bishe_demand').val()
				},
				dataType: 'json',
				success: function(data) {
					console.log(data)
					if(data.status == 0) {
						alert("修改成功");
						setTimeout(function() {
							$('.center').html('');
							$('.center').load('./teachercampus.html');
						}, 300)
					} else {
						alert("修改失败");
					}
				},
				error: function(err) {
					alert("请求异常，请重新登录！", function() {
						$(location).attr('href', './login.html');
					})
				}
			})
		})

		function xiugai(gid) {
			$.ajax({ //初始化毕设题目
				xhrFields: {
					withCredentials: true
				},
				type: 'get',
				url: getFullURL('sel-topic'),
				data: {
					gid: gid
				},
				dataType: 'json',
				success: function(data) {
					console.log(data)
					if(data.status == 0) {
						$('#bishe_title').val(data.topic.topic);
						$('#bishe_content').val(data.topic.content);
						$('#bishe_demand').val(data.topic.demand);
					}
				},
				error: function(err) {
					alert("请求异常，请重新登录！", function() {
						$(location).attr('href', './login.html');
					})
				}
			})
		}

		$('.shanchu').click(function() {
			$.ajax({ //删除校内毕设题目
				xhrFields: {
					withCredentials: true
				},
				type: 'get',
				url: getFullURL('teacher/del-topic'),
				data: {
					gid: $(this).val()
				},
				dataType: 'json',
				success: function(data) {
					console.log(data)
					if(data.status == 0) {
						alert('删除成功');
						setTimeout(function() {
							$('.center').html('');
							$('.center').load('./teachercampus.html');
						}, 300)
					} else {
						alert('删除失败')
					}
				},
				error: function(err) {
					alert("请求异常，请重新登录！", function() {
						$(location).attr('href', './login.html');
					})
				}
			})
		})

		//校外审核通过或未通过
		function shenhe_exbtn(flag, gid) {
			$.ajax({
				xhrFields: {
					withCredentials: true
				},
				type: 'post',
				url: getFullURL('teacher/tc-exotc'),
				data: {
					gid: gid,
					pass: flag
				},
				dataType: 'json',
				success: function(data) {
					console.log(data)
					if(data.status == 0) {
						alert('审核成功')
						setTimeout(function() {
							$('.center').html('');
							$('.center').load('./teachercampus.html');
						}, 300)
					} else {
						alert('暂无学生选报')
					}
				},
				error: function(err) {
					alert("请求异常，请重新登录！", function() {
						$(location).attr('href', './login.html');
					})
				}
			})
		}

		$('#xwtongguo').click(function() {
			shenhe_exbtn(2, $(this).val())
		})

		$('#xwbutongguo').click(function() {
			shenhe_exbtn(0, $(this).val())
		})

		//校内审核通过或者未通过
		function shenhe_btn(flag, gid) {
			var select_id = "#select_" + gid;
			$.ajax({
				xhrFields: {
					withCredentials: true
				},
				type: 'post',
				url: getFullURL('teacher/tc-extc'),
				data: {
					sno: $(select_id).val(),
					gid: gid,
					flag: flag
				},
				dataType: 'json',
				success: function(data) {
					console.log(data)
					if(data.status == 0) {
						alert('审核成功')
						setTimeout(function() {
							$('.center').html('');
							$('.center').load('./teachercampus.html');
						}, 300)
					} else {
						alert('暂无学生选报')
					}
				},
				error: function(err) {
					alert("请求异常，请重新登录！", function() {
						$(location).attr('href', './login.html');
					})
				}
			})
		}

		$('.pass').click(function() {
			shenhe_btn(2, $(this).val())
		})

		$('.nopass').click(function() {
			shenhe_btn(0, $(this).val())
		})

	}
</script>